dnl configure.in -- 
dnl ITIID           : $ITI$ $Header $__Header$
dnl Author          : Ulrich Pfeifer
dnl Created On      : Thu Mar 24 17:15:50 1994
dnl Last Modified By: Ulrich Pfeifer
dnl Last Modified On: Tue Jan 10 17:13:24 1995
dnl Update Count    : 234
dnl Status          : Unknown, Use with caution!
dnl 
dnl
dnl Process this file with autoconf to produce a configure script.
dnl
dnl MACROS
dnl
define(UP_ASK_FOR,
[echo "$2 ($3)?";
read $1;
if test "$$1" = "" ; then
        $1="$3";
fi])dnl
dnl
define(UP_PROG_DIFF,  [AC_PROGRAM_CHECK(DIFF,  diff,  diff,  :)])dnl
dnl
define(UP_HPUX,
[AC_CHECKING(for HPUX)
AC_BEFORE([$0], [AC_COMPILE_CHECK])AC_BEFORE([$0], [AC_TEST_PROGRAM])AC_BEFORE([$0], [AC_HEADER_EGREP])AC_BEFORE([$0], [AC_TEST_CPP])AC_PROGRAM_EGREP(yes,
[#ifdef hpux || __hpux
  yes
#endif
], AC_DEFINE(_HPUX_SOURCE))
])dnl
dnl
dnl INIT
dnl
AC_INIT(README)
AC_CONFIG_HEADER(Defaults.tmpl)
AC_REVISION($ITI$ $Header $__Header$)

FREE_WAIS_SF_VERSION="1.1" 
AC_SUBST(FREE_WAIS_SF_VERSION)
AC_DEFINE_UNQUOTED(FREE_WAIS_SF_VERSION,$FREE_WAIS_SF_VERSION)
DISTNAME="freeWAIS-sf"
AC_SUBST(DISTNAME)
AC_DEFINE_UNQUOTED(_DISTNAME_,$DISTNAME) 

FREE_WAIS_SF_VERSION_STRING="$DISTNAME Release $FREE_WAIS_SF_VERSION" 
AC_DEFINE_UNQUOTED(FREE_WAIS_SF_VERSION_STRING,\"$FREE_WAIS_SF_VERSION_STRING\")

echo 
echo You are about to build $FREE_WAIS_SF_VERSION_STRING
echo "This is *NOT* freeWAIS from CNIDR."
echo

dnl
dnl CHECK for compiler
dnl
CFLAGS='-g'
AC_SUBST(CFLAGS)
AC_PREFIX(waisserver)
AC_PROG_CC
AC_PROG_CPP
AC_PROGRAM_CHECK(PCPP,cpp,$dir/$word,PCPP=$CPP)
SAVE_PATH=$PATH 
PATH="${PATH} /lib /usr/lib"
AC_PROGRAM_CHECK(PCPP,cpp,,) 
PATH=$SAVE_PATH 
dnl
dnl DEFAULT SYSTEMS TESTS
dnl
UP_HPUX
AC_MINIX
AC_ISC_POSIX
AC_AIX
if test "$CC" = "gcc" ; then
   AIX=`echo "$DEFS" | grep '_ALL_SOURCE'`;
   if test "$AIX" != "" ; then
        echo "INFO: will use cc on AIX"
        CC=cc
   fi
fi
AC_DYNIX_SEQ
AC_IRIX_SUN
AC_SCO_INTL
AC_XENIX_DIR
COMPILER_VERSION=`$CC -v 2>&1 | sed -e '1 d'`
if test "$COMPILER_VERSION" = "" ; then
   COMPILER_VERSION=$CC
fi
AC_DEFINE_UNQUOTED(COMPILER_VERSION,\"$COMPILER_VERSION\")
dnl
dnl CHECK PROGRAMS
dnl
AC_GCC_TRADITIONAL
AC_PROG_RANLIB
if test "$srcdir" = "." ; then
    srcdir=`pwd`;
fi      
AC_PROG_INSTALL
if test -z "${INSTALL}"; then
    echo "Did not find an install which i would trust. Please add it to"
    echo "config.status after this ./configure run."
    echo ""
    echo "A valid setting could be:"
    echo ""
    echo "INSTALL='/usr/bin/install -c'"
else
    echo "Will use \"${INSTALL}\" for installation."
fi
AC_FIND_X
UP_PROG_DIFF
if test "$DIFF" = ":" ; then
    DIFF=cmp
fi
AC_PROG_LEX
AC_PROG_YACC
AC_PROGRAM_PATH(UNCOMPRESSOR,zcat,"zcat")
if test "$UNCOMPRESSOR" = "zcat" ; then
    echo "Warning: did not found \"zcat\" in your path"
else
    echo "Found zcat: \"$UNCOMPRESSOR\""
fi
AC_DEFINE_UNQUOTED(UNCOMPRESSOR,\"$UNCOMPRESSOR\")
AC_PROGRAM_PATH(UNZIPPER,gzcat,"gzcat")
if test "$UNZIPPER" = "gzcat" ; then
    echo "Warning: did not found \"gzcat\" in your path"
else
    echo "Found zcat: \"$UNZIPPER\""
fi
AC_DEFINE_UNQUOTED(UNZIPPER,\"$UNZIPPER\")
dnl
dnl HEADER
dnl
AC_STDC_HEADERS
AC_HAVE_HEADERS(memory.h unistd.h string.h sys/fcntl.h sys/select.h sys/shm.h netinet/in.h sys/socket.h netdb.h)
AC_HEADER_EGREP(getrnge, [regexp.h], AC_DEFINE(HAVE_GETRNGE))
dnl
dnl LIBRARIES
dnl
AC_COMPILE_CHECK(-lsocket needed,,[socket();]
,[echo "Your linker seems to be happy without -lsocket"],
AC_HAVE_LIBRARY(socket, [LIBS="$LIBS -lsocket"]))
AC_COMPILE_CHECK(-lnsl needed,,[gethostbyname();]
,[echo "Your linker seems to be happy without -lnsl" ; ],
AC_HAVE_LIBRARY(nsl, [LIBS="$LIBS -lnsl"]))
AC_COMPILE_CHECK(-lmalloc needed,,[malloc();]
,[echo "Your linker seems to be happy without -lmalloc" ; ],
AC_HAVE_LIBRARY(malloc, [LIBS="$LIBS -lmalloc"]))
dnl MachTen:
AC_HAVE_LIBRARY(cs, [LIBS="$LIBS -lcs"])
dnl
dnl FUNCTIONS
dnl
AC_ALLOCA
AC_HEADER_EGREP(alphasort, dirent.h, AC_DEFINE(HAVE_ALPHASORT))
AC_HEADER_EGREP(scandir, dirent.h, AC_DEFINE(HAVE_SCANDIR))
AC_HEADER_EGREP(remove, stdio.h, AC_DEFINE(HAVE_REMOVE))
AC_HEADER_EGREP(getcwd, unistd.h, AC_DEFINE(HAVE_GETCWD))
AC_HEADER_EGREP(getwd, unistd.h, AC_DEFINE(HAVE_GETWD))
AC_HAVE_FUNCS(memcpy bcopy memmove strdup)
dnl
dnl COMPILE TESTS
dnl
case "$DEFS" in
    *HAVE_MEMCPY* )
echo "Checking to see if your memcpy() can do overlapping copies..." 
AC_TEST_PROGRAM(
[
main()
{
char buf[128], abc[128];
char *b;
int len;
int off;
int align;

memcpy(abc, "abcdefghijklmnopqrstuvwxyz0123456789", 36);

for (align = 7; align >= 0; align--) {
	for (len = 36; len; len--) {
		b = buf+align;
		memcpy(abc, b, len);
		for (off = 1; off <= len; off++) {
			memcpy(b, b+off, len);
			memcpy(b+off, b, len);
			if (memcmp(b, abc, len))
				exit(1);
		}
	}
}
exit(0);
}

],[echo "Yes, it can." ; AC_DEFINE(MEMCPY_OVERLAP)], [echo "It can't, sorry."]) 
;;
esac

case "$DEFS" in
*HAVE_BCOPY*)
echo "Checking to see if your bcopy() can do overlapping copies..." 
AC_TEST_PROGRAM(
[
main()
{
char buf[128], abc[128];
char *b;
int len;
int off;
int align;
bcopy("abcdefghijklmnopqrstuvwxyz0123456789", abc, 36);

for (align = 7; align >= 0; align--) {
	for (len = 36; len; len--) {
		b = buf+align;
		bcopy(abc, b, len);
		for (off = 1; off <= len; off++) {
			bcopy(b, b+off, len);
			bcopy(b+off, b, len);
			if (bcmp(b, abc, len))
				exit(1);
		}
	}
}
exit(0);
}
],[echo "Yes, it can." ; AC_DEFINE(BCOPY_OVERLAP)], [echo "It can't, sorry."])
;;	
esac

AC_TIME_WITH_SYS_TIME
AC_STRUCT_TM
AC_CHAR_UNSIGNED
AC_CONST
AC_COMPILE_CHECK(inet_ntoa with struct argument, [
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
],[
struct sockaddr_in source;
inet_ntoa(source.sin_addr)
],AC_DEFINE(INET_NTOA_WITH_STRUCT),)
AC_COMPILE_CHECK(inet_ntoa with pointer argument, [
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
],[
struct sockaddr_in source;
inet_ntoa(&source.sin_addr)
],AC_DEFINE(INET_NTOA_WITH_POINTER),)

echo checking for [ctype].h
AC_TEST_PROGRAM(
[
#include <ctype.h>
#ifndef HAVE_BCOPY
#define bcopy(s, d, n) memcpy ((d), (s), (n))
#endif
unsigned char ctype[256];
main()
{
     bcopy(_ctype_,ctype,256*sizeof(char));
     exit(0);
}
],AC_DEFINE(CTYPEVAR,_ctype_))
echo checking for [regexp].h
AC_TEST_PROGRAM(
[
#define INIT register char *regexp=instring;
#define GETC() (*regexp++)
#define PEEKC() (*regexp)
#define UNGETC(c) (regexp--)
#define RETURN(pointer) return(0);          /* return 0 on sucess */
#define ERROR(val) return((char *) val);    /* return error code on failure */
#include <regexp.h>
main()
{
        circf = 1;
        exit(0);
}
],REGEXP=1,REGEXP=0;echo failed)


if test "1" = "$REGEXP" ; then
    UP_ASK_FOR(usereg,Do you want to use your systems [[regexp]].h,no)
    if test "$usereg" = "no" ; then
        REGEXP=0;
    fi      
fi
if test "0" = "$REGEXP" ; then
    {
    AC_DEFINE(SYSVREGEXP) 
    REGEXPLIB=[../regexp/libregexp.a]
    SUBDIRS=[regexp]
    echo "Ok, will use my own [regxep].h";
    }
else 
    echo "Ok, will stick with your REGXEP";
fi

UP_ASK_FOR(huge_headlines,Will you have HEADLINE files greater than 16 MB,no)

if test "$huge_headlines" = "yes" ; then
        {
        AC_DEFINE(HUGE_HEADLINES)dnl
        echo "Note that old indexes are invalid for the new server" ;
        }
else 
        echo "Ok, no huge headlines; old indexes remain valid" ;
fi


echo ""
echo You can compile freeWAIS-sf with it\'s own ctype package. You
echo should do this, if you want to use special "(country specific)"
echo chars, which are not supported by your systems ctype.

UP_ASK_FOR(iso,[Use your systems ctype],no)
if test "$iso" = "no" ; then
    echo "Ok, will use my own ctype";
    INC="${INC} -I../ctype"
    SUBDIRS="ctype ${SUBDIRS}"
    LFLAGS="${LFLAGS} -8"
    ISOOBJS=../ctype/ctype.o
    AC_DEFINE(ISO)
    echo ""
    echo I will now ask for your special letters.  If you do not want
    echo to give the now, edit Default.tmpl after this configure run.
    echo Input your upper case letters in the same order than your
    echo lower case letters. "toupper() and tolower()" depend on this
    echo order. Input letters wich are upper and lower case in both
    echo strings.

    UP_ASK_FOR(lchars, what are your lower case letters,"����")
    AC_DEFINE_UNQUOTED(LCHARS,\"$lchars\")
    UP_ASK_FOR(uchars, what are your upper case letters,"����")
    AC_DEFINE_UNQUOTED(UCHARS,\"$uchars\")
    if test "$LEX" != "flex" ; then
          echo "Note that you can not reconstruct ir/query_l.c from"
          echo "ir/query_l.l, since you don't have flex!";
    fi
else
    echo "Ok, will use your systems ctype";
fi

echo ""
echo You can compile and link the clients with the capability to
echo search [index] files directely. So you need not to install a
echo server, for local searches. The clients will be greater, but
echo faster with local searches.
echo You can not run the test without the switch

UP_ASK_FOR(local,Do you want to compile with -DLOCAL_SEARCH,yes)

if test "$local" = "yes" ; then
    echo "Ok, will compile with the -DLOCAL_SEARCH switch"
    AC_DEFINE(LOCAL_SEARCH)
    LIBLOCAL=../ir/liblocal.a
    TESTDIR="FIELD-EXAMPLE"
    AC_SUBST(TESTDIR)
else
    echo "Ok, will compile with no -DLOCAL_SEARCH switch"
    echo "Note: will not be able to run the tests"
fi

echo ""
echo "You can modify the URL document type, to put the URL of the"
echo "indexed in the document id instead of the headline. If you use"
echo "this modification you can customize the headline (e.g. with the"
echo "-t fields option). Also it is not required to keep a copy of the"
echo "documents for retrieval with the wais server. But currently only"
echo "SFgate can handle this modified docids. Normal clients will not"
echo "correctely interprete the docids and try to retrieve the document"
echo "from a wais instead of the correspondig http server."
echo ""

UP_ASK_FOR(urldocid,Do you want to use the modified URL handling,no)

if test "$urldocid" = "no" ; then
    echo "Ok, will use the original doctype URL"
else
    echo "Ok, will use the modified URL doctype"
    echo "Note: you will not be able to retrieve URL documents with"
    echo "      clients other than SFgate"
    AC_DEFINE(URLDOCID)
fi

if test "$prefix" = "" ; then
    prefix="/usr/local/wais";
fi 

UP_ASK_FOR(INSTALLROOT,Where should the installation go,$prefix)
prefix="$INSTALLROOT" 
echo "Ok, will install in $INSTALLROOT"


case "$DEFS" in
    *HAVE_SYS_SHM* )
echo "

I added a patch from Alberto Accomazzi for speeding up usage of
synonym files. He writes about his patch:

For those of you who have fairly large synonym files (> 10Kb) and are
running the software on a machine that supports shared memory (your
machine does) enabling this feature will speed up the waisserver
response time by a significant factor.

For those of you who do not have shared memory, I have rewritten the
memory allocation part of synonym.c so that bigger memory chunks are
allocated and used rather than allocating memory for each word and
synonym, so the code should be a little faster for you too.
"

UP_ASK_FOR(CACHE_SYN,Do you want to use shm cache,no)
    if test "$CACHE_SYN" != "no" ; then
        echo "Ok. The shared memory support will be compiled in."
        AC_DEFINE(CACHE_SYN)
    else
        echo "Ok. Will not compile the shared memory support."
    fi
;;
esac

echo "

As distributed, $FREE_WAIS_SF_VERSION_STRING will send an UDP packet
to my workstation every time waisserver reindexes his info database,
containing your (numeric) UID, your operating system, your compiler
version and the $DISTNAME version.

This is JUST because I would like to get an idea of to which
systems/compilers $DISTNAME has be ported and how many people use it,
and keep on using it (rather than "tried it once" folks).  It will
NEVER become a licensing scheme or some crazy thing like that.  But,
you can disable it by answering 'yes' to the following question.  If
you do that, please let me know, if you are running $DISTNAME on a
system/compiler, which is not mentioned in the README.
"

UP_ASK_FOR(DO_NOT_TELL_ABOUT_ME,Disable the UDP packet sending,no)
if test "$DO_NOT_TELL_ABOUT_ME" = "yes" ; then
    AC_DEFINE(DO_NOT_TELL_ABOUT_ME)
    echo "Ok. I'll respect your privacy."
else
    echo "Ok. Thank you for your trust."
fi 

AC_SUBST(DIFF) 
AC_SUBST(INSTALLROOT) 
AC_SUBST(INC) 
AC_SUBST(LFLAGS)
AC_SUBST(ISOOBJS) 
AC_SUBST(REGEXPLIB) 
AC_SUBST(LIBLOCAL)
AC_SUBST(x_includes) 
AC_SUBST(x_libraries) 
AC_SUBST(SUBDIRS)
generate_imake=1
AC_SUBST(generate_imake) 

AC_OUTPUT([[Install.tmpl Makefile ctype/Makefile regexp/Makefile
lib/Makefile ir/Makefile ui/Makefile x/Makefile
FIELD-EXAMPLE/Makefile]])

echo 
echo finished setup 
echo "

Compile with 'make'.

Install with 'make install' and 'make install.man'. If you want to
link the wais libraries into other systems (Mosaic, gopher) then type
'make install.lib' before cleaning with 'make clean'. 'make veryclean'
will in addition remove the tests databases in FIELD-EXAMPLE and the
files generated by flex, bison, latex, dvips.

If you have imake you can alternatively enter

'xmkmf -a'
'make'
'make install'
'make install.man'
'make install.lib'

In the x subdirectory the latter is preferred.

Note, that the Makefiles created by this script do not contain any
dependencies.  If you change some setting, recomplile the whole
distribution or use imake/makedepend to generate the dependencies.

To recreate the autoconf Makefiles enter

'config.status'

Good luck!
";
